{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">

                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">
                            <input type="text" id="keyword" class="layui-input search" name="keyword" value="" placeholder="标题"/>
                        </div>
                        <!--<div class="layui-input-inline" style="margin-top: 5px">-->
                            <!--<select name="banner_type" class="layui-input">-->
                                <!--<option value="">不限类型</option>-->
                                <!--<option value="1">图文</option>-->
                                <!--<option value="2">视频</option>-->
                            <!--</select>-->
                        <!--</div>-->
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="pb_where" class="layui-input">
                                <option value="">不限展示位置</option>
                                <option value="1">轮播图</option>
                                <option value="2">优惠</option>
                                <option value="3">佣金</option>
                                <option value="4">精英团队</option>
                                <option value="5">团队招聘</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.layer_show('新建图片文件', '{:url('bannerAdd')}?type=1')">
                            <i class="fa fa-image"></i> 添加
                        </button>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <button  class="btn btn-warning m-l-xs layuiBtn" data-type="getCheckDataSet">
                            <i class="fa fa-del"></i> 启用为列表显示的两张图
                        </button>
                        <button  class="btn btn-danger m-l-xs layuiBtn" data-type="getCheckData">
                            <i class="fa fa-del"></i> 批量删除
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                    <script type="text/html" id="staBar3">
                        {{# if(d.pb_where == 4){ }}
                        <input type="checkbox" value="{{d.pb_id}}"  lay-skin="switch"  lay-text="是|否" lay-filter="OnOff3" {{ d.pb_info_top == 2 ? 'checked' : '' }}  >
                        {{# }else{ }}
                        --
                        {{# } }}
                    </script>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        {{# if(d.pb_type == 1){ }}
                        <img src="{{d.pb_url}}" class="table-img" onerror="this.src='/static/admin/images/head_default.gif'"/>
                        {{# } }}
                        {{# if(d.pb_type == 2){ }}
                        <a href="{{d.pb_url}}" target="_blank" style="color: cornflowerblue">查看视频</a>
                        {{# } }}
                    </script>
                    <script type="text/html" id="pb_where">
                        {{# if(d.pb_where == 1){ }}
                        轮播图
                        {{# } }}
                        {{# if(d.pb_where == 2){ }}
                        优惠
                        {{# } }}
                        {{# if(d.pb_where == 3){ }}
                        佣金
                        {{# } }}
                        {{# if(d.pb_where == 4){ }}
                        精英团队
                        {{# } }}
                        {{# if(d.pb_where == 5){ }}
                        团队招聘
                        {{# } }}

                    </script>

                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.layer_show('编辑/详情', '{:url('bannerEdit')}?pb_id={{d.pb_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil">编辑</i></a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.pb_id}}','{:url('bannerDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Member/newBanner")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [10, 15, 20, 50, 100, 300]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left'},
                  {type:'numbers', width: 60, title: '序号'}
                , {field: 'pb_url', width: 110, title: '缩略图', align: 'center', templet: '#imgTpl'}
                , {field: 'pb_sort', width: 110, title: '排序(可编辑)', align: 'center', edit: 'test'}
                , {field: 'pb_title_up', width: '', title: '上标题', align: 'center'}
                , {field: 'pb_title', width: '', title: '下标题', align: 'center'}
                , {field: 'pb_where', width: '', title: '展示位置', align: 'center', toolbar: '#pb_where'}
                , {field: 'pb_time', width: 160, title: '新建时间', align: 'center'}
                , {field: 'status',fixed: 'right', width: 100, title: '是否推荐', align: 'center', templet: '#staBar3'}
                , {fixed: 'right', width: 150, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.table-img').viewer({
                    url: 'data-original',
                });
            }
        });

        //监听状态开关操作
        form.on('switch(OnOff3)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 2: num = 1;
            //用户状态
            wk.status(this.value,num, '{:url("changeMainStatus")}',obj);
        });
        //监听单元格编辑---排序
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
            wk.change(data.pb_id,"{:url('updateBannerSort')}",field,value);
        });
        //批量操作
        var $ = layui.$, active = {
            getCheckData: function(){
                //批量删除
                wk.batchDel(getIds(),"{:url('batchDel')}");
            },
            getCheckDataSet: function(){
                //批量启用
                wk.usingAll(getIds(),'',"{:url('batchSetTwoPics')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['pb_id'])
            });
            return ids;
        }

    });
</script>
</body>
</html>